package com.ivan.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ivan.cmn.mapper.DictMapper;
import com.ivan.model.entity.cmn.Dict;
import com.ivan.model.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/*
 * @Author      Ivan
 * @Date        2023/4/3 13:34
 * @Description
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {
    //构造器注入
    private DictMapper dictMapper;
    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
     * 一行一行的读，从第二行开始
     * @param dictEeVo
     * @param analysisContext
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        dictMapper.insert(dict);
//        System.out.println(dict);
    }

    /**
     * 读取完毕执行
     * @param analysisContext
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
